<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课程表管理</title>
    <link rel="stylesheet" href="./styles.css">
    <script src="./common.js"></script>
</head>
<body>
    <div class="container">
        <h1>课程表管理</h1>
        <div id="tableContainer"></div>
        <button onclick="showAddForm()">添加课程</button>
        <div id="addForm" style="display: none;">
            <input type="text" id="name" placeholder="课程名称">
            <button onclick="addCourse()">确认添加</button>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            loadTable('courses');
        });

        function showAddForm() {
            document.getElementById('addForm').style.display = 'block';
        }

        async function addCourse() {
            const data = {
                课程名称: document.getElementById('name').value
            };
            const success = await addData('courses', data);
            if (success) {
                alert('课程添加成功');
                window.location.reload();
            } else {
                alert('课程添加失败');
            }
        }
    </script>
</body>
</html>
